bitcoin-ruby(create tx)
require 'bitcoin'
Bitcoin.network = :testnet3
code:tx
tx = Bitcoin::Protocol::Tx.new
tx.lotck_time = 1571736000
prev_tx_hash = "txid"
prev_output_index = "index"
tx_in = Bitcoin::Protocol::TxIn.from_hex_hash(prev_tx_hash, prev_output_index)
tx.add_in(tx_in)
address = "address"
value = "value"
tx_out = Bitcoin::Protocol::TxOut.value_to_address(value, address)
tx.add_out(tx_out)
code:鍵
secret_key = "secret_key"
key = Bitcoin::Key.from_base58(secret_key)
code:署名
redeem_script = "redeem_script"
script_pubkey = "script_pubkey"
prev_script_pubkey = Bitcoin::Script.new(script_pubkey.htb)
prev_tx_value = "value"
tx.in0.script_sig = Bitcoin::Script.new(Bitcoin::Script.pack_pushdata(redeem_script.htb)).to_payload sig_hash = tx.signature_hash_for_witness_input(0, redeem_script.htb, prev_tx_value)
sig = key.sign(sig_hash) + [Bitcoin::Script::SIGHASH_TYPE:all].pack("C") tx.in0.script_witness.stack << sig tx.in0.script_witness.stack << key.pub.htb